package com.onlineMIS.ORM.DAO.headQ.user;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.onlineMIS.ORM.DAO.BaseDAO;
import com.onlineMIS.ORM.entity.headQ.inventory.InventoryOrder;
import com.onlineMIS.ORM.entity.headQ.supplier.finance.FinanceBillSupplier;
import com.onlineMIS.ORM.entity.headQ.user.SystemRoleMenu;
import com.onlineMIS.ORM.entity.headQ.user.SystemRoleMenu;
import com.onlineMIS.ORM.entity.headQ.user.UserInfor;
import com.onlineMIS.common.Common_util;
import com.onlineMIS.filter.SystemParm;

@Repository
public class SystemRoleMenuDaoImpl extends BaseDAO<SystemRoleMenu> {



	/**
	 * 根据角色id和菜单id查询
	 * @param roleId
	 * @param menuId
	 * @return
	 */
	public  SystemRoleMenu getSystemRoleMenu(int roleId, int menuId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(SystemRoleMenu.class);
		criteria.add(Restrictions.eq("roleId", roleId));
		criteria.add(Restrictions.eq("menuId", menuId));
		List<SystemRoleMenu> SystemRoleMenu = getByCritera(criteria,true);
		if (SystemRoleMenu.size() !=0) {
			return SystemRoleMenu.get(0);
		}else {
			return null;
		}
		
	}

	
	/**
	 * 根据角色ID查询角色权限信息
	 * @param chainRoleTypeId
	 * @return
	 */
	public List<SystemRoleMenu> selectFunctionsByRoleId(int roleId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(SystemRoleMenu.class);
		criteria.add(Restrictions.eq("roleId", roleId));
		List<SystemRoleMenu> SystemRoleMenu = getByCritera(criteria,true);
		return SystemRoleMenu;
	}


	public void deleteRoleMenus(int roleId) {
		String sql = " delete FROM SystemRoleMenu  WHERE roleId = ?";
		List<Object> list = new ArrayList<Object>();
		list.add(roleId);		
		this.executeHQLUpdateDelete(sql, list.toArray(), true);		
	}



}
